import React from "react";
import { HashRouter, Routes, Route, Navigate } from "react-router-dom";
import Login from "../views/login/Login";
import NewsSandBox from "../views/sandbox/NewsSandBox";
export default function IndexRouter() {
  return (
    <HashRouter>
      {/* Routes 和 Switch 的功用是一样的，都能做到精准匹配 */}
      <Routes>
        <Route path="/login" element={<Login />} />
        {/* <Route path="/" element={<NewsSandBox />} /> */}
        <Route
          path="/*"
          element={
            localStorage.getItem("token") ? (
              <NewsSandBox />
            ) : (
              <Navigate to="/login" />
            )
          }
        />
      </Routes>
    </HashRouter>
  );
}
